#include <string.h>
#include <stdio.h>
#include "label.h"
#include "../memory.h"
#include "../render.h"

may_lable_t *label_create(void *parent, int x, int y, const char *text)
{
    may_lable_t *lable = memory_alloc(sizeof(may_lable_t));

    lable->obj.widget_type = widget_type_lable;
    lable->obj.x = x;
    lable->obj.y = y;
    lable->obj.h = 16;
    lable->obj.w = strlen(text) * 8;
    strcpy(lable->text, text);
    if(parent)
    {
        list_add_tail(&lable->obj.node, &((widget_t *)parent)->node);
    }
    return lable;
}

void label_remove(may_lable_t *lable)
{
    list_del(&lable->obj.node);

    memory_free(lable->text);
    memory_free(lable);
}

void label_set_text(may_lable_t *lable, const char *text)
{
    strcpy(lable->text, text);
}


void label_render(void *obj)
{
    may_lable_t* lable = (may_lable_t*)obj;
    render_draw_text(lable->obj.x, lable->obj.y, lable->text);
}